function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}

var a = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../utils/config.js")), e = require("../../utils/api.js"), s = require("../../utils/util.js"), i = (require("../../wxParse/wxParse.js"), 
require("../../utils/wxApi.js"), require("../../utils/wxRequest.js")), n = a.default.getPageCount, o = getApp().vPush;

getApp();

Page({
    data: {
        postsList: [],
        postsShowSwiperList: [],
        isLastPage: !1,
        page: 1,
        search: "",
        categories: 0,
        showerror: "none",
        showCategoryName: "",
        categoryName: "",
        showallDisplay: "block",
        displayHeader: "none",
        displaySwiper: "none",
        floatDisplay: "none",
        displayfirstSwiper: "none",
        currentIndex: 0,
        topNav: []
    },
    formSubmit: function(t) {
        var a = "../list/list", e = "";
        "" != (e = "search-input" == t.currentTarget.id ? t.detail.value : t.detail.value.input) ? (a = a + "?search=" + e, 
        wx.navigateTo({
            url: a
        })) : wx.showModal({
            title: "提示",
            content: "请输入内容",
            showCancel: !1
        });
    },
    onShareAppMessage: function() {
        return {
            title: a.default.getWebsiteName + " - 专注于自媒体小程序开发与定制",
            path: "pages/index/index",
            success: function(t) {},
            fail: function(t) {}
        };
    },
    onPullDownRefresh: function() {
        this.setData({
            showerror: "none",
            showallDisplay: "none",
            displaySwiper: "none",
            floatDisplay: "none",
            isLastPage: !1,
            page: 0,
            postsShowSwiperList: []
        }), this.fetchTopFivePosts();
    },
    onReachBottom: function() {
        var t = this;
        t.data.isLastPage ? console.log("最后一页") : (t.setData({
            page: t.data.page + 1
        }), console.log("当前页" + t.data.page), this.fetchPostsData(t.data));
    },
    onLoad: function(t) {
        var e = this;
        this.fetchTopFivePosts(), e.setData({
            topNav: a.default.getIndexNav
        });
    },
    vPushHandler: function(t) {
        o.add(t);
    },
    handleChange: function(t) {
        this.setData({
            currentIndex: t.detail.current
        });
    },
    onShow: function(t) {
        wx.setStorageSync("openLinkCount", 0);
    },
    fetchTopFivePosts: function() {
        var a = this;
        i.getRequest(e.getSwiperPosts()).then(function(e) {
            if ("200" == e.data.status && e.data.posts.length > 0) {
                var s;
                a.setData((s = {
                    postsShowSwiperList: e.data.posts
                }, t(s, "postsShowSwiperList", a.data.postsShowSwiperList.concat(e.data.posts.map(function(t) {
                    return null != t.post_medium_image_300 && "" != t.post_medium_image_300 || (null != t.content_first_image && "" != t.content_first_image ? t.post_medium_image_300 = t.content_first_image : t.post_medium_image_300 = "../../images/logo700.png"), 
                    t;
                }))), t(s, "showallDisplay", "block"), t(s, "displaySwiper", "block"), s));
            } else a.setData({
                displaySwiper: "none",
                displayHeader: "block",
                showallDisplay: "block"
            });
        }).then(function(t) {
            a.fetchPostsData(a.data);
        }).catch(function(t) {
            console.log(t), a.setData({
                showerror: "block",
                floatDisplay: "none"
            });
        }).finally(function() {});
    },
    fetchPostsData: function(t) {
        var a = this;
        t || (t = {}), t.page || (t.page = 1), t.categories || (t.categories = 0), t.search || (t.search = ""), 
        1 === t.page && a.setData({
            postsList: []
        }), wx.showLoading({
            title: "正在加载",
            mask: !0
        }), i.getRequest(e.getPosts(t)).then(function(t) {
            200 === t.statusCode ? (t.data.length < n && a.setData({
                isLastPage: !0
            }), a.setData({
                floatDisplay: "block",
                postsList: a.data.postsList.concat(t.data.map(function(t) {
                    var a = t.date;
                    return null != t.category_name ? t.categoryImage = "../../images/category.png" : t.categoryImage = "", 
                    null != t.post_thumbnail_image && "" != t.post_thumbnail_image || (t.post_thumbnail_image = "../../images/logo700.png"), 
                    t.date = s.cutstr(a, 10, 1), t;
                }))
            }), setTimeout(function() {
                wx.hideLoading();
            }, 900)) : "rest_post_invalid_page_number" == t.data.code ? (a.setData({
                isLastPage: !0
            }), wx.showToast({
                title: "没有更多内容",
                mask: !1,
                duration: 1500
            })) : wx.showToast({
                title: t.data.message,
                duration: 1500
            });
        }).catch(function(e) {
            1 == t.page ? a.setData({
                showerror: "block",
                floatDisplay: "none"
            }) : (wx.showModal({
                title: "加载失败",
                content: "加载数据失败,请重试.",
                showCancel: !1
            }), a.setData({
                page: t.page - 1
            }));
        }).finally(function(t) {
            wx.hideLoading(), wx.stopPullDownRefresh();
        });
    },
    loadMore: function(t) {
        var a = this;
        a.data.isLastPage ? wx.showToast({
            title: "没有更多内容",
            mask: !1,
            duration: 1e3
        }) : (a.setData({
            page: a.data.page + 1
        }), this.fetchPostsData(a.data));
    },
    redictDetail: function(t) {
        var a = "../detail/detail?id=" + t.currentTarget.id;
        wx.navigateTo({
            url: a
        });
    },
    onNavRedirect: function(t) {
        var a = t.currentTarget.dataset.redicttype, e = null == t.currentTarget.dataset.url ? "" : t.currentTarget.dataset.url, s = null == t.currentTarget.dataset.appid ? "" : t.currentTarget.dataset.appid, i = null == t.currentTarget.dataset.extraData ? "" : t.currentTarget.dataset.extraData;
        "apppage" == a ? wx.navigateTo({
            url: e
        }) : "webpage" == a ? (e = "../webpage/webpage?url=" + e, wx.navigateTo({
            url: e
        })) : "miniapp" == a && wx.navigateToMiniProgram({
            appId: s,
            envVersion: "release",
            path: e,
            extraData: i,
            success: function(t) {},
            fail: function(t) {
                console.log(t);
            }
        });
    },
    redictAppDetail: function(t) {
        var a = t.currentTarget.id, e = t.currentTarget.dataset.redicttype, s = null == t.currentTarget.dataset.url ? "" : t.currentTarget.dataset.url, i = null == t.currentTarget.dataset.appid ? "" : t.currentTarget.dataset.appid;
        "detailpage" == e && (s = "../detail/detail?id=" + a, wx.navigateTo({
            url: s
        })), "apppage" == e ? wx.navigateTo({
            url: s
        }) : "webpage" == e ? (s = "../webpage/webpage?url=" + s, wx.navigateTo({
            url: s
        })) : "miniapp" == e && wx.navigateToMiniProgram({
            appId: i,
            envVersion: "release",
            path: s,
            success: function(t) {},
            fail: function(t) {
                console.log(t);
            }
        });
    },
    redictHome: function(t) {
        t.currentTarget.dataset.id;
        wx.switchTab({
            url: "/pages/index/index"
        });
    }
});